/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "engine_Plugin.h"

#include "材质/材质.h"
#include "材质/预设材质.h"

#include "物体/物体.h"



S_着色线管* f_enginePlugin_创建线管(S_设备环境& ctx, const S_着色器创建配置& 线管创建配置, S_线管创建参数& 线管参数) {
	
	S_着色线管* 着色线管 = (S_着色线管*)malloc(sizeof(S_着色线管));
	
	着色线管->m_Shader = f_create着色(ctx, 线管创建配置);
	着色线管->m_Pipeline = f_create线管(ctx, *着色线管->m_Shader, 线管参数);
	着色线管->m_Shader->f_alloc参数设置(&(着色线管->m_GPU参数set));

    return 着色线管;
}

void f_enginePlugin_销毁线管(S_着色线管* 着色线管) {
	delete 着色线管->m_Shader;
	delete 着色线管->m_Pipeline;

	free(着色线管);
}




static void f_updateGPU参数配置_数值标注(S_材质管线* mat, S_物体* ob, S_Mesh* mesh, uint8 元素, uint32 多维子元素) {
	S_数值标注材质* sm = (S_数值标注材质*)(mat);
	f_df_allocGPU参数缓存槽(&mesh->m_多维材质槽[多维子元素].m_参数槽, 3);
	
	mesh->m_多维材质槽[多维子元素].m_参数槽.m_参数槽[2] = &ob->m_实例颜色[元素];
	mesh->m_多维材质槽[多维子元素].m_参数槽.m_绑定位置[2] = DEF_BINDING_WIDGET_Color;
	mesh->m_多维材质槽[多维子元素].m_参数槽.m_参数类型[2] = E_板载缓存类型::e_SSBO;
	mesh->m_多维材质槽[多维子元素].m_参数槽.m_绑定数量[2] = 1;

	mesh->m_多维材质槽[多维子元素].m_参数槽.m_纹理槽 = &sm->纹理槽;
}

S_材质管线* f_enginePlugin_创建材质(S_着色线管* 线管, bool 创建光追材质, bool 创建物理光照材质) {
	
	S_材质管线* 材质 = f_material_createPBR();

	if (创建物理光照材质) {
		
	}

	材质->mf_GPU参数配置;
	材质->m_材质属性;
	return 材质;
}

void f_enginePlugin_销毁材质(S_材质管线* 材质) {
	f_material_releasePBR(材质);


}

S_Material& f_enginePlugin_材质属性(S_材质管线* 材质) {
	return f_bm_at<S_Material>(材质->m_材质属性, 0);
}







